/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.dominatingspecies.frontend.element;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.IChoiceRenderer;

/**
 *
 * @author Ondrej Prazak
 */
public class EnumChoiceRenderer<T extends Enum<T>> implements IChoiceRenderer<T> {

    /**
     * The Component used a the root of the I18N search process
     */
    private final Component resourceProvider;

    /**
     * Constructor
     *
     * @param resourceProvider The component to use as the root of the I18N
     * search process
     */
    public EnumChoiceRenderer(final Component resourceProvider) {
        this.resourceProvider = resourceProvider;
    }

    @Override
    public Object getDisplayValue(final T value) {
        final String key = EnumKeyProvider.getKey(value);
        return resourceProvider.getString(key);
    }

    @Override
    public String getIdValue(final T object, final int index) {
        final Enum<?> enumValue = object;
        return enumValue.name();
    }
}
